//
//  MIXMainTabBarController.m
//  WEIBO
//
//  Created by Mix on 16/5/12.
//  Copyright © 2016年 Mix. All rights reserved.
//

#import "MIXMainTabBarController.h"
#import "MIXHomeViewController.h"
#import "MIXMessageViewController.h"
#import "MIXDiscoverViewController.h"
#import "MIXProfileViewController.h"
#import "MIXMianTabBar.h"

@interface MIXMainTabBarController ()

@end

@implementation MIXMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //为tabBar染色，修改的是选中item后的颜色
    [UITabBar appearance].tintColor = [UIColor orangeColor];
    
    //设置子控制器
    [self setupChildController];
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //自定义tabBar
    MIXMianTabBar * mainTB = [[MIXMianTabBar alloc] init];
    //错误写法
//    [self.tabBar setValue:mainTB forKey:@"tabBar"];
    //正确写法，两种都可以--设置自定义的tabBar
//    [self setValue:mainTB forKeyPath:@"tabBar"];
    [self setValue:mainTB forKey:@"tabBar"];
    mainTB.callBlock = ^(){
        NSLog(@"modal出控制器");
    };
}

//设置子控制器
-(void)setupChildController {
    
    //获取子控制器
    MIXHomeViewController * homeVC = [[MIXHomeViewController alloc] init];
    [self addChildViewController:homeVC withTitle:@"首页" andImageName:@"tabbar_home"];
    
    MIXMessageViewController * messageVC = [[MIXMessageViewController alloc] init];
    [self addChildViewController:messageVC withTitle:@"消息" andImageName:@"tabbar_message_center"];
    
    MIXDiscoverViewController * discoverVC = [[MIXDiscoverViewController alloc] init];
    [self addChildViewController:discoverVC withTitle:@"发现" andImageName:@"tabbar_discover"];
    
    MIXProfileViewController * profileVC = [[MIXProfileViewController alloc] init];
    [self addChildViewController:profileVC withTitle:@"我" andImageName:@"tabbar_profile"];
    
}

//添加子控制器
-(void)addChildViewController:(UIViewController *)childController withTitle:(NSString *)title andImageName:(NSString *)imageName {
    
    //设置控制器标题
    childController.title = title;
    
    //设置控制器图片
    childController.tabBarItem.image = [UIImage imageNamed:imageName];
    
    //为每个子控制器包一个导航控制器
    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:childController];
    //添加到tabBarController上
    [self addChildViewController:nav];
    
    
}









@end
